

<style>
    .td{
        line-height: normal;
        word-wrap: break-word;
        word-break: break-all;
        margin-top: 5px;
        padding-top: 10px;
    }
</style>

<div class="padding-big">
    <div class="op">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始时间：</label>
                <div class="layui-input-inline">
                    <input type="date" name="from" id="from" lay-verify="date" placeholder="yyyy-MM-dd"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline" style="margin-left: 0px">
                <label class="layui-form-label">结束时间：</label>
                <div class="layui-input-inline">
                    <input type="date" name="to" id="to" lay-verify="date" placeholder="yyyy-MM-dd"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" id="username" maxlength="16" lay-verify="title" autocomplete="off"
                           placeholder="请输入用户名" class="layui-input">
                </div>
            </div>
            <button class="layui-btn layui-btn-normal" id="warnSearch"><i class="fa fa-search"></i>&nbsp;搜索</button>
            <button class="layui-btn layui-btn-normal" id="saveWarn" onclick="saveWarnLog()"><i class=""></i>&nbsp;点击备份告警日志</button>
            <button class="layui-btn layui-btn-normal" id="wStatisticalBtn"><i class="fa fa-line-chart"></i>&nbsp;点击查看统计信息</button>
        </div>
    </div>
    <div class="offcial-table margin-top clearfix" style="background-color: #fff;">
        <div class="offcial-table tr-border margin-big-top clearfix">
            <div class="tr-th clearfix">
                <div class="th w15">
                      <span style="margin-left: 30px;">
                    告警模块
                    <i class="fa fa-arrow-circle-up fa-gray fa-fw" title="按告警模块名升序排列" id="moduleNameAesc" style="cursor: pointer"></i>
                    <i class="fa fa-arrow-circle-down fa-gray fa-fw" title="按告警模块名降序排列" id="moduleNameDesc" style="cursor: pointer"></i>
                      </span>
                </div>
                <div class="th w12">
                    <span style="margin-left: 30px;">
                    告警类型
                    <i class="fa fa-arrow-circle-up fa-gray fa-fw" title="按告警类型升序排列" id="warnTypeAesc" style="cursor: pointer"></i>
                    <i class="fa fa-arrow-circle-down fa-gray fa-fw" title="按告警类型降序排列" id="warnTypeDesc" style="cursor: pointer"></i>
                    </span>
                </div>
                <div class="th w13">
                          <span style="margin-left: 30px;">
                    告警级别
                    <i class="fa fa-arrow-circle-up fa-gray fa-fw" title="按告警级别升序排列" id="warnLevelAesc" style="cursor: pointer"></i>
                    <i class="fa fa-arrow-circle-down fa-gray fa-fw" title="按告警级别降序排列" id="warnLevelDesc" style="cursor: pointer"></i>
                          </span>
                </div>
                <div class="th w15">
                          <span style="margin-left: 30px;">
                    用户名
                    <i class="fa fa-arrow-circle-up fa-gray fa-fw" title="按用户名升序排列" id="usernameAesc" style="cursor: pointer"></i>
                    <i class="fa fa-arrow-circle-down fa-gray fa-fw" title="按用户名降序排列" id="usernameDesc" style="cursor: pointer"></i>
                          </span>
                </div>
                <div class="th w20">
                    告警详情
                </div>
                <div class="th w10">
                    IP地址
                </div>
                <div class="th w15">
                          <span style="margin-left: 30px;">
                    告警时间
                    <i class="fa fa-arrow-circle-up fa-gray fa-fw" title="按告警时间升序排列" id="warnTimeAesc" style="cursor: pointer"></i>
                    <i class="fa fa-arrow-circle-down fa-gray fa-fw" title="按告警时间降序排列" id="warnTimeDesc" style="cursor: pointer"></i>
                          </span>
                </div>
            </div>

            <div id="tbody">
            </div>
        </div>
    </div>

    <div class="show-page padding-big-right">
        <div class="page">
            <div class="page">
                <p style="font-size: 14px">
                    符合条件的信息共:&nbsp;<span id="numValue" style="color: red;">0 </span>&nbsp;条
                </p>
                <ul class="offcial-page margin-top margin-big-right">
                    <li>
                        <a href="javascript:void(0)" onclick="logsWarningFirstPage()" class="next" >首     页</a>
                    </li>
                    <li>
                        <a href="javascript:void(0)" onclick="logsWarningLastPage()" class="next">上一页</a>
                    </li>
                    <li><span class="fl">第<em class="margin-small-left margin-small-right" id="pageNum">1</em>页</span>
                    </li>
                    <li>
                        <a href="javascript:void(0)" onclick="logsWarningNextPage()" class="next">下一页</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

</div>
<script>

    //延迟任务查询当前本地告警日志文件是否即将到达上限
    // setTimeout(function(){
    //     $.ajax({
    //         url:HOST.concat("/getwarnlogarrivedmax?token="+config.token+"&timeStamp="+new Date().getTime()),
    //         type:"get",
    //         dataType:"json",
    //         success:function(data){
    //             if (data.meta.state=="success"){
    //                 var res=data.data.isAlert;
    //                 if (res==true||res=="true"){
    //                     alert(data.data.message);
    //                 }
    //             } else{
    //                 console.log("查询失败");
    //             }
    //         },
    //         error:function (data) {
    //             console.log("服务器异常");
    //         }
    //     });
    // },5000);



    /**
     * 告警日志统计接口
     * */
    $("#wStatisticalBtn").die().live("click",function(){
        $("#contentArea").empty();
        $.get("warnStatisticalInfo.html",function(data){
            $("#contentArea").html(data);
        });
    });

    var num=1;
    var dataInfo={
        "username":"",
        "fromTime":"",
        "toTime":"",
        "moduleNameSort":"",
        "warnTypeSort":"",
        "warnLevelSort":"",
        "warnTimeSort":"",
        "usernameSort":"",
        "click":"false"
    };


    /**
     * 查询告警日志记录接口
     * @param pageNum
     * @param pageSize
     * @param callback
     */
    function listWarningLogsByCond(username, from, to, pageNum, pageSize){
        isOnline("sysAuditor");
        $.ajax({
            url: HOST.concat("/listWarningLogInfo?username="+username
                +"&fromTime="+ from
                + "&toTime="+ to
                +"&pageNum=" + pageNum
                + "&pageSize=" + pageSize
                +"&moduleNameSort="+dataInfo.moduleNameSort
                +"&warnTypeSort="+dataInfo.warnTypeSort
                +"&warnLevelSort="+dataInfo.warnLevelSort
                +"&warnTimeSort="+dataInfo.warnTimeSort
                +"&usernameSort="+dataInfo.usernameSort
                    +"&click="+dataInfo.click
                + "&token=" + config.token) ,
            type: "GET",
            success: function(datas){
                checkLogin(datas);
                //console.log(datas);
                num=pageNum;
                addWarningContent(datas);
            },
            error: function(){
                console.log("请求日志列表错误！");
            },
            dataType: "json"
        });
        //window.location.href=HOST.concat("/storesLog?username="+username + "&token=" + config.token+"&type=warn");
    }
    /**
     * 转存告警日志
     * */
    function saveWarnLog() {
        isOnline("sysAuditor");
        window.location.href=HOST.concat("/storesLog?username="+getSessionStorage("username")+ "&token=" + config.token+"&type=warn");
    }
    /**
     * 获取指定页码的告警日志
     * */
    function getWarningLogsInfoList(pageNum){
        listWarningLogsByCond(dataInfo.username, dataInfo.fromTime, dataInfo.toTime, pageNum, pageSize);
    }

    /**
     * 告警日志
     * */
    function addWarningContent(res){
        //查询成功
        // console.log(res);
        if(res.meta.state==="success") {
            var list = res.data.resArray;
            // console.log("有查询记录");
            $("#numValue").text(res.data.resCount);
            $("#tbody").empty();
            $("#pageNum").text(num);
            addTd(list);
        }
        //查询失败
        else if(res.meta.state=="failed"){
            if(num==1){
                $("#tbody").empty();
                $("#numValue").text(0);
                //alert("无查询结果!");
            }else {
               // alert(res.meta.message);
                alert("已经是最后一页")
                num--;
            }
        }
    }

    /**
     * 获取上一页
     * */
    function logsWarningLastPage(){
        if(num<=1){
            num = 1;
            alert("已经是第一页!");
            $("#pageNum").text(num);
        }else{
            num--;
            dataInfo.click="false";
            getWarningLogsInfoList(num);
        }
    }

    /**
     * 获取下一页
     * */
    function logsWarningNextPage(){
        num++;
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    }

    /**
     * 获取首页
     * */
    function logsWarningFirstPage(){
        if(num==1){
            alert("已经是首页!");
        }else{
            num = 1;
            $("#pageNum").text(num);
            dataInfo.click="false";
            getWarningLogsInfoList(num);
        }
    }

    /**
     * 添加具体日志内容
     * */
    function addTd (list){
        for (var p in list) {
            var item = list[p];//单条数据
            var createTime = item["createTime"];
            var warningType = item["warningType"];
            var warningModuleName = item["warningModuleName"];
            var warningLevel = item["warningLevel"];
            var ipAddress = item["ipAddress"];
            var warningInfo = item["warningInfo"];
            var username = item["username"];

            $("#tbody").append("<div class=\"op-data tr clearfix border-bottom-none\">" +
                "                        <div class=\"td w15\">" + warningModuleName + "</div>" +
                "                        <div class=\"td w12\">" + warningType + "</div>" +
                "                        <div class=\"td w13\">" + warningLevel + "</div>" +
                "                        <div class=\"td w15\">" + username + "</div>" +
                "                        <div class=\"td w20\" style='text-indent: 2em;'>" + warningInfo + "</div>" +
                "                        <div class=\"td w10\">" + ipAddress + "</div>" +
                "                        <div class=\"td w15\">" + createTime + "</div>" +
                "               </div>");
        }
    }

    /**
     * 点击搜索
     * */
    $("#warnSearch").die().live("click",function(){
        dataInfo.username=$("#username").val();
        dataInfo.fromTime=$("#from").val();
        dataInfo.toTime=$("#to").val();
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="true";

        if( dataInfo.username.trim()!="" && !checkLogUsername(dataInfo.username)){
            alert("用户名不能超过16位，且不包含除出下划线和减号以外的特殊字符");
            $("#username").val("");
            return;
        }

        if(!isNull(dataInfo.fromTime)&&!isNull(dataInfo.toTime)) {
            if (compareFromAndTo(dataInfo.fromTime,dataInfo.toTime)){
                dataInfo.fromTime = dataInfo.fromTime.replace(/-/g, "/") + " 00:00:00";
                dataInfo.toTime = dataInfo.toTime.replace(/-/g, "/") + " 23:59:59";
            }else{
                alert("时间区间先后存在问题!");
                return false;
            }
        }else if(!isNull(dataInfo.fromTime)){
            dataInfo.fromTime = dataInfo.fromTime.replace(/-/g, "/") + " 00:00:00";
        }else if(!isNull(dataInfo.toTime)){
            dataInfo.toTime = dataInfo.toTime.replace(/-/g, "/") + " 23:59:59";
        }
        num=1;
        getWarningLogsInfoList(num);
    });

    /**
     * 点击告警模块升降序排序
     * */
    $("#moduleNameAesc").live("click",function () {
        dataInfo.moduleNameSort="0";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    $("#moduleNameDesc").live("click",function () {
        dataInfo.moduleNameSort="1";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });

    /**
     * 点击告警类型升降排序
     * */
    $("#warnTypeAesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="0";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    $("#warnTypeDesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="1";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    /**
     * 点击告警级别升降排序
     * */
    $("#warnLevelAesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="0";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    $("#warnLevelDesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="1";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    /**
     * 点击告警时间升降排序
     * */
    $("#warnTimeAesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="0";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    $("#warnTimeDesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="1";
        dataInfo.usernameSort="";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });

    /**
     * 按用户名排序
     * */
    $("#usernameAesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="0";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });
    $("#usernameDesc").live("click",function () {
        dataInfo.moduleNameSort="";
        dataInfo.warnTypeSort="";
        dataInfo.warnLevelSort="";
        dataInfo.warnTimeSort="";
        dataInfo.usernameSort="1";
        dataInfo.click="false";
        getWarningLogsInfoList(num);
    });

    //进入页面就直接请求
    getWarningLogsInfoList(1);
</script>


